Use indirect field access for types spanning multiple inexact compilation units#129830
Draft
jtschuster wants to merge 1 commit into
Draft
Use indirect field access for types spanning multiple inexact compilation units#129830jtschuster wants to merge 1 commit into
jtschuster wants to merge 1 commit into
Conversation
…tion units Fixes the Verify_FieldOffset failfast in crossgen2-composite Large Version Bubble R2R legs (dotnet#128968). When a reference type's layout chain spans 2+ inexact compilation units, crossgen2 conservatively aligns the derived type's fields after a cross-compilation-unit base. At runtime those framework modules can instead bind into a single composite image, where the runtime back-fills the derived fields into the base type's trailing alignment padding. Neither a baked relative (ENCODE_FIELD_BASE_OFFSET) nor absolute offset is valid for both layouts, so route these fields to an indirect, runtime-resolved field offset (ENCODE_FIELD_OFFSET), which is correct regardless of how the modules are grouped and emits no layout-verification fixup. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates crossgen2 ReadyToRun field-access encoding to avoid baking field offsets for reference types whose layout can differ at runtime when their layout “spans” multiple inexact compilation units, which can otherwise trigger Verify_FieldOffset failfasts (and potentially incorrect field accesses when verification is off).
Changes:
- In
EncodeFieldBaseOffset, detectHasMultipleInexactCompilationUnitsfor the owning type and switch to an indirect, runtime-resolved field offset encoding (ENCODE_FIELD_OFFSETviaSymbolNodeFactory.FieldOffset). - Ensure this indirection path runs before the existing
IsInheritanceChainLayoutFixedInCurrentVersionBubble(...)decision so a potentially unstable baked offset isn’t used.
Member
Author
|
/azp run runtime-coreclr crossgen2-composite |
|
Azure Pipelines successfully started running 1 pipeline(s). |
This was referenced Jun 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #128968.
Problem
In crossgen2-composite Large Version Bubble (LVB) R2R test legs (compiled with
--verify-type-and-field-layout), the runtime hits aVerify_FieldOffsetfailfast, e.g.:Root cause
This is a cross-module layout divergence between crossgen2 and the runtime:
The two layouts disagree, so a baked relative offset (
ENCODE_FIELD_BASE_OFFSET) or absolute offset with a relative field-offset verification is invalid for one of them — producing the failfast (and, with verification off, an incorrect memory access).This reproduces for types like
UnixConsoleStream._useReadLine(System.Console+ corelib) andXmlJsonReader._complexTextMode(System.Private.DataContractSerialization+System.Private.Xml+ corelib).Fix
In
EncodeFieldBaseOffset, whenTypeLayoutCompilationUnits(pMT).HasMultipleInexactCompilationUnitsis true, route field access to an indirect, runtime-resolved field offset (ENCODE_FIELD_OFFSETviaSymbolNodeFactory.FieldOffset). This is correct regardless of how the modules are ultimately grouped and emits no layout-verification fixup. The new branch is placed before theIsInheritanceChainLayoutFixedInCurrentVersionBubblebranch, which would otherwise bake a wrong offset for these types.Validation
Validated end-to-end against a composite framework image (
framework-r2r.dll) plus a separately-compiled test composite, the exact configuration that triggered the failure:binarytrees-6(writes to Console ->UnixConsoleStream): passed, no assert.JsonBenchmarksSerialize/Deserialize (DataContractJsonSerializer->XmlJsonReader): passed, no assert.straceconfirmed bothframework-r2r.dlland the patched testcomposite-r2r.dllare loaded in-process during the run (not a JIT fallback).Note
This pull request was authored with the assistance of GitHub Copilot.